<?php

/**
 * Description of WebUser
 *
 * @author Marco Mounzer
 * @file WebUser
 * @copyright 2013
 * $Id: WebUser $
 */
require_once 'Database.php';

class WebUser extends ObjectForm {

    public $Id;
    public $email;
    public $nome;
    public $cognome;
    public $password;

    public function __construct() {
        $this->Id = 0;
    }

    protected $formFields = array('Id' => ObjectForm::TYPE_HIDDEN,
        'email' => ObjectForm::TYPE_INPUT,
        'password' => ObjectForm::TYPE_PASSWORD,
        'nome' => ObjectForm::TYPE_INPUT,
        'cognome' => ObjectForm::TYPE_INPUT,
    );
    protected $formFieldsDescriptors = array();

    public static function FindUser($username, $password) {
        $table = Database::getTableNameFromClassName(new WebUser());

        $sql = "SELECT id FROM $table WHERE email = " . Database::GetIstance()->quote($username) . " AND password = " . Database::GetIstance()->quote($password);

        $res = Database::GetIstance()->select($sql);

        if (count($res) != 1)
            return false;

        $record = $res[0];

        return Database::GetIstance()->loadObject(new self, $record->id);
    }

}